﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using System.Data;

namespace DataAccess.Classes
{
   public class BinhLuanBaiViet
    {
        public int IDBinhLuan { get; set; }
        public int MaBaiViet { get; set; }
        public string IDNguoiDung { get; set; }
        public string NoiDung { get; set; }
        public DateTime Ngay { get; set; }
        public BinhLuanBaiViet() { }


        public static bool ThemBaiViet(BinhLuanBaiViet bl)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQueryWithOutput("IDBinhLuan", "BinhLuanBaiViet_Them", bl.IDBinhLuan, bl.MaBaiViet, bl.IDNguoiDung, bl.NoiDung, bl.Ngay);
                return Convert.ToInt32(rs) > 0;
            }
            catch
            {
                return false;
            }
        }

        public static List<BinhLuanBaiViet> LayDanhSachBinhLuan(string albumImagesID, string page, out int howManyPages)
        {
            IDataReader reader = null;
            try
            {
                //int pageSize = GlobalConfiguration.PageSize;
                int pageSize = 4;
                reader = DataProvider.Instance.ExecuteReader("BinhLuan_BaiViet", Convert.ToInt32(albumImagesID),
                                                            GlobalConfiguration.DescriptionLength, Convert.ToInt32(page),
                                                            pageSize);
                reader.Read();
                howManyPages = (int)Math.Ceiling((double)reader.GetInt32(0) / (double)pageSize);
                reader.NextResult();
                return CBO.FillCollection<BinhLuanBaiViet>(reader);
            }
            catch
            {
                if (reader != null && reader.IsClosed == false) reader.Close();
                howManyPages = 0; return new List<BinhLuanBaiViet>();
            }
        }
    }
}
